import dayjs from "dayjs"
import CryptoJS from 'crypto-js';
import hdyConfig from "@/config/index";

export function getTimeUntilNow(dateTime) {
	dateTime = dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss');
	// console.log(dateTime)
	var dateTimeStamp = new Date(dateTime.replace(/-/g, '/')).getTime()
	var minute = 1000 * 60;
	var hour = minute * 60;
	var day = hour * 24;
	var halfamonth = day * 15;
	var month = day * 30;
	var now = new Date().getTime();
	var diffValue = now - dateTimeStamp;
	var result = '';
	if (diffValue < 0) {
		return;
	}
	var monthC = diffValue / month;
	var weekC = diffValue / (7 * day);
	var dayC = diffValue / day;
	var hourC = diffValue / hour;
	var minC = diffValue / minute;

	if (monthC >= 1) {
		result = "" + parseInt(monthC) + "月前";
	} else if (weekC >= 1) {
		result = "" + parseInt(weekC) + "周前";
	} else if (dayC >= 1) {
		result = "" + parseInt(dayC) + "天前";
	} else if (hourC >= 1) {
		result = "" + parseInt(hourC) + "小时前";
	} else if (minC >= 1) {
		result = "" + parseInt(minC) + "分钟前";
	} else {
		result = "刚刚";
	}
	// console.log(`[info] ${result}`)
	return result

}

export function searchSourceName(value) {
	var res = ''
	if (value == 1) {
		res = '全网客源'
	} else if (value == 2) {
		res = '精准客源'
	} else if (value == 3) {
		res = '同城客源'
	} else if (value == 4) {
		res = '附近客源'
	} else {
		res = '全部来源'
	}
	return res
}


export function returnFloat(num) {
	num = num.toString(); // 转成字符串类型  如能确定类型 这步可省去
	if (num.indexOf(".") !== -1) {
		let [integerPart, decimalPart] = num.split(".");

		if (decimalPart.length > 2) {
			decimalPart = decimalPart.substring(0, 2);
		} else if (decimalPart.length === 1) {
			decimalPart += "0";
		}

		num = `${integerPart}.${decimalPart}`;
	} else {
		num += ".00";
	}

	return num;
}